// 类模板做函数参数
#include <iostream>
#include <string>
using namespace std;
template<class T1 = string, class T2 = int >
class Person
{
public:
    T1 m_name;
    T2 m_age;
    Person(T1 name, T2 age)
    {
        this->m_name = name;
        this->m_age = age;
    }
    void showPerson()
    {
        cout << "name: " << this->m_name << "  age: " << this->m_age << endl;
    }
};
// 1.指定参数类型
void print1(Person<string, int> &p)
{
    p.showPerson();
}
void test1()
{
    Person<string, int> p1("lxy", 20);
    print1(p1);
}
// 2. 参数模板化
template<class T1, class T2>
void print2(Person<T1, T2> &p)
{
    p.showPerson();
    cout << "T1 type: " << typeid(T1).name() << endl;
    cout << "T2 type: " << typeid(T2).name() << endl;
}
void test2()
{
    Person<string, int> p2("lxy", 21);
    print2(p2);
    Person<string, string> p3("lxy", "22");
    print2(p3);
}
// 3. 整个类模板化
template<class T>
void print3(T &p)
{
    p.showPerson();
    cout << "T type: " << typeid(T).name() << endl;
}
void test3()
{
    Person<string> p4("lxy", 24);
    print3(p4);
}

int main(void)
{
    test1();
    test2();
    test3();

    return 0;
}